/* The file is part of the Waff web framework.
 *
 * Copyright (c) 2011, Grzegorz Skorupa
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditionsare met:
 *
 * - Redistributions of source code must retain the above copyright notice, this list of conditions
 *   and the following disclaimer.
 * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions
 *   and the following disclaimer in the documentation and/or other materials provided with the distribution.
 * - Neither the name of the Grzegorz Skorupa nor the names of its contributors may be used to endorse or promote products
 *   derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package pl.org.waff;

import javax.servlet.http.HttpServletRequest;
import java.util.Properties;

/**
 *
 * @author greg
 */
public class DefaultPathProcessor implements PathProcessor{

    //private static String jspPrefixForMobileDevices = null;
    //private static String jspPrefixForStandardDevices = null;
    //private static boolean mobileDeviceHandling = false;
    //private static String deviceDomainArgumentName;
    //private static Properties properties;

    public void init(Properties newproperties) {
        //this.properties=(Properties)newproperties.clone();
        //jspPrefixForMobileDevices = properties.getProperty("mobiledevice.jspprefix");
        //jspPrefixForStandardDevices = properties.getProperty("standarddevice.jspprefix");
        //mobileDeviceHandling = Boolean.getBoolean(properties.getProperty("mobiledevice.handling", "false"));
        //deviceDomainArgumentName = properties.getProperty("devicedomain.argument.name", "deviceDomain");
    }

    public String modifyPath(String path, HttpServletRequest req) {
        String newPath=path;
        //if(path!=null){
            //newPath=modifyPathForMobile(path, req);
        //}
        return newPath;
    }

    /*public String modifyPathForMobile(String path, HttpServletRequest req) {
        String ret = path;
        if (!mobileDeviceHandling || path==null) {
            return ret;
        }
        String deviceName = req.getHeader("User-Agent");
        boolean isMobileDevice = false;
        if (null != deviceName) {
            isMobileDevice = deviceName.indexOf("Android") >= 0;
        }
        if (isMobileDevice) {
            if (jspPrefixForMobileDevices.length() >= 0) {
                if (null != jspPrefixForStandardDevices && jspPrefixForStandardDevices.length() > 0) {
                    if (path.startsWith(jspPrefixForStandardDevices)) {
                        ret = path.replaceFirst(jspPrefixForStandardDevices, jspPrefixForMobileDevices);
                    } else {
                        ret = jspPrefixForMobileDevices + path;
                    }
                } else {
                    ret = jspPrefixForMobileDevices + path;
                }
            }
        }
        return ret;
    }*/

    /*
    public String modifyPathForMobileOld(String path, HttpServletRequest req) {
        String ret = path;
        Boolean mobileDeviceDomain = (Boolean) req.getSession().getAttribute(deviceDomainArgumentName);
        boolean isMobileDevice = false;
        if (null != mobileDeviceDomain) {
        isMobileDevice = mobileDeviceDomain.booleanValue();
        }
        return ret;
    }*/
}
